﻿// Copyright (C) 2012 Jeff Tanner <jeff00seattle@gmail.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.IO;
using System.Configuration;
using System.Diagnostics;

using WindowsAzure_REST;

namespace WindowsAzure_FileBackup_Common
{
    partial class Common
    {
        protected static StorageConnectionMode WindowsAzureConnectionModeAppConfig
        {
            get
            {
                string connectionType = ConfigurationManager.AppSettings["WindowsAzureConnectionMode"];
                return (StorageConnectionMode)Enum.Parse(typeof(StorageConnectionMode), connectionType);
            }
        }

        protected static string WindowsAzureCloudStorageEndpointAppConfig
        {
            get
            {
                return ConfigurationManager.AppSettings["WindowsAzureCloudStorageEndpoint"];
            }
        }

        protected static string WindowsAzureLocalStorageEndpointAppConfig
        {
            get
            {
                return ConfigurationManager.AppSettings["WindowsAzureLocalStorageEndpoint"];
            }
        }

        protected static string WindowsAzureLocalStorageAccountNameAppConfig
        {
            get
            {
                return ConfigurationManager.AppSettings.Get("WindowsAzureLocalStorageAccountName");
            }
        }
        protected static string WindowsAzureLocalStorageAccountKeyAppConfig
        {
            get
            {
                return ConfigurationManager.AppSettings.Get("WindowsAzureLocalStorageAccountKey");
            }
        }
        protected static string WindowsAzureStorageBlobContainerNameAppConfig
        {
            get
            {
                return ConfigurationManager.AppSettings.Get("WindowsAzureStorageBlobContainerName");
            }
        }

        /// <summary>
        /// Gets a blob container delete sleep.
        /// </summary>
        public int BlobContainerDeleteSleepAppConfig
        {
            get
            {
                try
                {
                    string sBlobContainerDeleteSleep = ConfigurationManager.AppSettings["WindowsAzureFileBackupSvcBlobContainerDeleteSleep"];
                    return System.Convert.ToInt32(sBlobContainerDeleteSleep, 10);
                }
                catch (Exception ex)
                {
                    this.EventLog.WriteEntry(
                        String.Format("BlobContainerDeleteSleepAppConfig: Exception: {0}", ex.Message),
                        EventLogEntryType.Error
                      );
                }

                return 0;
            }
        }

        /// <summary>
        /// Gets a blob container delete sleep.
        /// </summary>
        public bool BlobContainerDeleteAppConfig
        {
            get
            {
                Common.WindowsAzureStorageBlobContainerDelete = false;

                try
                {
                    Common.WindowsAzureStorageBlobContainerDelete = (Convert.ToBoolean(ConfigurationManager.AppSettings.Get("WindowsAzureFileBackupSvcBlobContainerDelete").ToString())); ;
                }
                catch (Exception ex)
                {
                    this.EventLog.WriteEntry(
                        String.Format("BlobContainerDeleteAppConfig | Exception: {0}", ex.Message),
                        EventLogEntryType.Error
                        );
                }

                return Common.WindowsAzureStorageBlobContainerDelete;
            }
        }

        public static string EventLogNameAppConfig
        {
            get
            {
                return ConfigurationManager.AppSettings.Get("EventLogName").ToString();
            }
        }

        public static string EventLogSourceAppConfig
        {
            get
            {
                return ConfigurationManager.AppSettings.Get("EventLogSource").ToString();
            }
        }
    }
}
